package com.dduggs.note.RE;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式测试
 */
public class PasswordRegexp {

    /**
     * 判断是否是大陆手机号码11位数
     *
     * @param str 手机号码
     */
    public static boolean isRightPhoneLegal(String str) {
        String regExp = "^(316|13[0-9]|14[5|7|9]|15[0|1|2|3|5|6|7|8|9]|17[0|1|3|5|6|7|8]|18[0|1|2|3|5|6|7|8|9])[0-9]{8}$";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(str);
        return m.matches();
    }
    public static boolean isNumeric(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() ){
            return false;
        }
        return true;
    }


    public static boolean passStrong(String str){
        Pattern pattern = Pattern.compile("^((?=.*\\d)(?=.*\\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{6,}$");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() ){
            return false;
        }
        return true;
    }
    /**
     * 统一社会信用代码校验
     * @param str
     * @return
     */
    public static boolean isCreditCode(String str){
        Pattern pattern = Pattern.compile("^[0-9A-Za-z]{15}$");
        Pattern pattern2 = Pattern.compile("^[0-9A-Za-z]{18}$");
        Matcher matcherOne = pattern.matcher(str);
        Matcher matcherTwo = pattern2.matcher(str);

        if( matcherOne.matches()||matcherTwo.matches() ){
            return true;
        }else{
            return false;
        }
    }

    public static void main(String[] args) {
        String test = "2aaa[//..';[;jjj6786";
        Boolean res = passStrong(test);
        System.out.println(res);
    }
}
